<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Permission extends Model
{
	use SoftDeletes;

    protected $table = 'permission';

    protected $fillable = [
    	'permission_name','pid','route_url'
	];


	/**
	 * 多对多关联角色权限表
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/24 0024 15:32
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
	 */
	public function role_permission()
    {
		return $this->belongsToMany(Role::class,'role_permission','permission_id','role_id');
    }


    //关联自身，获得上级权限名称 -- 纯属学习自关联
	public function parent()
	{
		return $this->hasOne(get_class($this),'id','pid');
	}

	//获得下级
	public function children()
	{
		return $this->hasMany(get_class($this), 'pid', $this->getKeyName());
	}
}
